var carousel_val;
var server_path;
$(document).ready(function(){




server_path = $("#server_path").val();

        $('.carousel_container div:first div:first div:first').trigger('click');
   
	$('.wysiwyg-editor').ace_wysiwyg({
		toolbar:
		[
			'font',
			null,
			'fontSize',
			null,
			{name:'bold', className:'btn-info'},
			{name:'italic', className:'btn-info'},
			{name:'strikethrough', className:'btn-info'},
			{name:'underline', className:'btn-info'},
			null,
			{name:'insertunorderedlist', className:'btn-success'},
			{name:'insertorderedlist', className:'btn-success'},
			{name:'outdent', className:'btn-purple'},
			{name:'indent', className:'btn-purple'},
			null,
			{name:'justifyleft', className:'btn-primary'},
			{name:'justifycenter', className:'btn-primary'},
			{name:'justifyright', className:'btn-primary'},
			{name:'justifyfull', className:'btn-inverse'},
			null,
			{name:'createLink', className:'btn-pink'},
			{name:'unlink', className:'btn-pink'},
			null,
			{name:'insertImage', className:'btn-success'},
			null,
			'foreColor',
			null,
			{name:'undo', className:'btn-grey'},
			{name:'redo', className:'btn-grey'}
		]
	}).prev().addClass('wysiwyg-style2');

// for file upload





});

function save_page_details(page_id){
	open_spiner();
	sendData = $("#page_descriptions").serialize()+'&page_id='+page_id;
	$(".wysiwyg-editor").each(function(){
		id = $(this).attr('id');
		
		sendData=sendData+'&'+id+'='+$(this).html();
	});
	$.ajax({
		type: "POST",
		url: server_path+"libs/site_pages_ajax.php",
		data: sendData,
		// dataType:'json',
		success: function(data){		

			close_spiner();	
		}
	});
}
  $(function() {
            $('#file_upload').uploadify({
                'auto':true,
                'multi': true,
                'method'   : 'post',
                'swf'      : server_path+'js/uploadify/uploadify.swf',
                'uploader' : server_path+'libs/upload_photo.php',
                'onUploadStart' : function(file) {
                    $('#file_upload').uploadify('settings', 'formData', {
                        'upload_carousel' : 1,
                        'page_id' : $("#page_id").val()
                    });
                },
                 'onUploadSuccess':function(file,data,response){                  
                    $(".carousel_container").append(data);
                                  
                } 
            });
            $("#file_upload-button").addClass("btn");
            $("#file_upload-button").addClass("btn-primary");
            $("#file_upload-button span").addClass("Adauga poza");
        });

 $(function() {
            $('#file_upload_pics').uploadify({
                'auto':true,
                'multi': true,
                'method'   : 'post',
                'swf'      : server_path+'js/uploadify/uploadify.swf',
                'uploader' : server_path+'libs/upload_photo.php',
                'onUploadStart' : function(file) {
                    $('#file_upload_pics').uploadify('settings', 'formData', {
                        'upload_pictures' : 1,
                        'page_id' : $("#page_id").val()
                    });
                },
                 'onUploadSuccess':function(file,data,response){                  
                    $("#page_pictures").prepend(data);
                  
                             
                } 
            });
            $("#file_upload_pics-button").addClass("btn");
            $("#file_upload_pics-button").addClass("btn-primary");
            $("#file_upload_pics-button span").addClass("Adauga poza");
        });

function delete_carousel_img(id,button){
    sendData = 'delete_carousel_img='+id;
    bootbox.confirm("Are you sure?", function(result) {

    $.ajax({
        type: "POST",
        url: server_path+"libs/site_pages_ajax.php",
        data: sendData,
        // dataType:'json',
        success: function(data){        
            $(button).parent().parent().remove();
            bootbox.alert("Item deleted.");
        }
    });
    }); 
}
function update_carousel(name,id,value,lang_id){
sendData = 'update_carousel=1&name='+name+'&id='+carousel_val+'&value='+value+'&language_id='+lang_id;
  $.ajax({
        type: "POST",
        url: server_path+"libs/site_pages_ajax.php",
        data: sendData,
        // dataType:'json',
        success: function(data){        
            
        }
    });
}
function get_carousel_info(carousel,div){
    $(".carousel_container div div.span2").css("background-color","#F9F9F9");
    $(div).parent().css("background-color","#87B87F");
     sendData = 'get_carousel_info='+carousel;
     carousel_val=carousel;
  $.ajax({
        type: "POST",
        url: server_path+"libs/site_pages_ajax.php",
        data: sendData,
        dataType:'json',
        success: function(data){        
            $.each(data ,function( key, value ) {
                $("#"+key).val(value);
            });
        }
    });  
}
function delete_page_img(ceva,obj,site_page){
    bootbox.confirm("Are you sure?", function(result) {
    sendData = "delete_picture_page="+ceva+"&site_page="+site_page;
     $.ajax({
        type: "POST",
        url: server_path+"libs/site_pages_ajax.php",
        data: sendData,       
        success: function(data){        
             $(obj).parent().remove();
        }
    });  
 });
}